<?php
include_once ROOT.'/model/dao/ProductDao.php';
$productDao = new ProductDao();
header('Content-type: application/json');
$limit = 8;
$products = $productDao->findAll();
$router = Router::getInstance();
$info = $router->getInfo();

if(empty($info['lastindex']) && !(is_numeric($info['lastindex']) && $info['lastindex']>=0)){
	die();
}
$toJson = array();
for ($i=(int)$info['lastindex']; $i<(int)$info['lastindex']+$limit; $i++){
	if(empty($products[$i])){
		break;
	}
	$product = $products[$i];
	$values = array('img'=>getRoute('imgfromprod', $product->getId()),
				   'title'=>$product->getTitle(),
				   'description'=>$product->getDescription(),
				   'price'=>$product->getPrice(),
				   'number'=>$product->getNumber(),
				   'id'=>$product->getId());
	$toJson[] = $values;
}
echo json_encode($toJson);